﻿using System.Windows.Input;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using WinRTFramework.Interfaces.Navigation.Page;

namespace SeriesManager.View
{
    public sealed partial class FrameView : NavigationView
    {
        public FrameView()
        {
            this.InitializeComponent();
            this.Loaded += FrameView_Loaded;
        }

        void FrameView_Loaded(object sender, RoutedEventArgs e)
        {
            this.searchBox.SetBinding(SearchBox.QueryTextProperty, new Binding() { Source = DataContext, Path = new PropertyPath("SearchQuery"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
        }

        public Frame Navi
        {
            get { return this.NavigationFrame; }
        }

        protected override void UpdateVisualState(Size windowSize)
        {
            if (windowSize.Width < 920)
            {
                VisualStateManager.GoToState(this, "Width500", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "Width920", true);
            }
        }

        private void Popup_Opened(object sender, object e)
        {
            this.popUpChild.Width = (Window.Current.Bounds.Width - (Window.Current.Bounds.Width / 3));
            this.popUp.HorizontalOffset = (Window.Current.Bounds.Width - this.popUpChild.Width) / 2;
            this.popUp.VerticalOffset = (Window.Current.Bounds.Height - this.popUpChild.ActualHeight - 100) / 2;
            this.searchBox.Focus(FocusState.Programmatic);
        }
    }
}
